cache-workhorse:
  extends:
    - .default-retry
    - .default-before_script
    - .ruby-cache
    - .setup-test-env-cache
    - .caching:rules:cache-workhorse
  stage: prepare
  variables:
    SETUP_DB: "false"
  script:
    - source scripts/gitlab_component_helpers.sh
    - 'gitlab_workhorse_archive_doesnt_exist || { echoinfo "INFO: Exiting early as package exists."; exit 0; }'
    - run_timed_command "scripts/setup-test-env"
    - run_timed_command "select_gitlab_workhorse_essentials"
    - run_timed_command "create_gitlab_workhorse_package"
    - run_timed_command "upload_gitlab_workhorse_package"
  artifacts:
    expire_in: 7d
    paths:
      - ${TMP_TEST_GITLAB_WORKHORSE_PATH}/

.cache-assets-base:
  extends:
    - .compile-assets-base
    - .assets-compile-cache
    - .caching:rules:cache-assets
  stage: prepare
  variables:
    WEBPACK_REPORT: "false"
  script:
    - yarn_install_script
    - export GITLAB_ASSETS_HASH=$(bundle exec rake gitlab:assets:hash_sum)
    - source scripts/gitlab_component_helpers.sh
    - 'gitlab_assets_archive_doesnt_exist || { echoinfo "INFO: Exiting early as package exists."; exit 0; }'
    - assets_compile_script
    - echo -n "${GITLAB_ASSETS_HASH}" > "cached-assets-hash.txt"
    - run_timed_command "create_gitlab_assets_package"
    - run_timed_command "upload_gitlab_assets_package"

cache-assets:test:
  extends: .cache-assets-base

cache-assets:test as-if-foss:
  extends:
    - .cache-assets-base
    - .as-if-foss
    - .caching:rules:cache-assets-as-if-foss

cache-assets:production:
  extends:
    - .cache-assets-base
    - .production

packages-cleanup:
  extends:
    - .default-retry
    - .caching:rules:packages-cleanup
  image: ${GITLAB_DEPENDENCY_PROXY_ADDRESS}ruby:${RUBY_VERSION}
  stage: prepare
  before_script:
    - source scripts/utils.sh
    - install_gitlab_gem
  script:
    - scripts/packages/automated_cleanup.rb
